package me.zhengjie.minbearwcs.serivce.agv;

import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.agv.inf.AgvMissionDao;
import me.zhengjie.minbearwcs.dao.agv.inf.AgvMissionDetailDao;
import me.zhengjie.minbearwcs.entity.DTO.agv.TUSK.TUSKFeedBackTask;
import me.zhengjie.minbearwcs.entity.DTO.agv.task.actionEnum.AgvAction;
import me.zhengjie.minbearwcs.entity.PO.agv.AgvMissionDetail;
import me.zhengjie.observer.caster.WcsMulticaster;
import me.zhengjie.observer.event.DefaultEvent;
import me.zhengjie.observer.type.agv.AgvActionEventType;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class AgvService {

    private final AgvMissionDao agvMissionDao;
    private final AgvMissionDetailDao agvMissionDetailDao;
    private final WcsMulticaster wcsMulticaster;


    public boolean feedbackTask(TUSKFeedBackTask tuskFeedBackTask) {

        AgvMissionDetail agvMissionDetail = agvMissionDetailDao.selectByTaskIdAndPoint(tuskFeedBackTask.getTaskId(), tuskFeedBackTask.getTargetPoint());

        if (agvMissionDetail == null) {
            wcsMulticaster.multicastEvent(DefaultEvent.create(tuskFeedBackTask), AgvActionEventType.PUT_AMEND);
        } else if (AgvAction.GET.name().equals(agvMissionDetail.getAction())) {
            wcsMulticaster.multicastEvent(DefaultEvent.create(tuskFeedBackTask), AgvActionEventType.GET);
        } else if (AgvAction.PUT.name().equals(agvMissionDetail.getAction())) {
            wcsMulticaster.multicastEvent(DefaultEvent.create(tuskFeedBackTask), AgvActionEventType.PUT);
        }

        return true;
    }


}
